package jdbc.homework;

import jdbc.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class PwdDemo {
    public static void main(String[] args) {
        try(Connection conn= DBUtil.getConnection()) {
            Scanner sc = new Scanner(System.in);
            PreparedStatement ps = conn.prepareStatement("update user set password=?," +
                    "nickname=?,age=? where username=?");
            System.out.println("请输入用户名:");
            ps.setString(4,sc.nextLine());
            System.out.println("请输入新密码:");
            ps.setString(1,sc.nextLine());
            System.out.println("请输入新昵称:");
            ps.setString(2,sc.nextLine());
            System.out.println("请输入新年龄:");
            ps.setInt(3,Integer.parseInt(sc.nextLine()));
            System.out.println(ps.executeUpdate()>0?"修改成功":"修改失败");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
